//
//  CustomTabBar.m
//  OCWeiBo
//
//  Created by 江潘 on 15/6/25.
//  Copyright © 2015年 江潘. All rights reserved.
//

#import "CustomTabBar.h"
@interface CustomTabBar()
@property (nonatomic,strong) UIButton *composeBtn;
@end

static int btnCount =5;

@implementation CustomTabBar

- (instancetype)initWithFrame:(CGRect)frame {

    if (self = [super initWithFrame:frame]) {
        
        self.tintColor = [UIColor orangeColor];
    }
    
    return self;
}

- (UIButton *)composeBtn{
    
    if (_composeBtn == nil) {
        
        _composeBtn = [[UIButton alloc] init];
        
        [_composeBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [_composeBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        [_composeBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
         [_composeBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    }
    
    return _composeBtn;
}

- (void)setupUI{
    
    int index = 0;
    
    [self addSubview:self.composeBtn];
    
    CGFloat w = [UIScreen mainScreen].bounds.size.width / btnCount;
    
    CGRect rect = CGRectMake(0, 0, w, self.frame.size.height);
 
    for (UIView *v in self.subviews) {
        
        if ([v isKindOfClass:[UIControl class]] && ![v isKindOfClass:[UIButton class]]) {
            
            v.frame = CGRectOffset(rect, index * w, 0);
            
            index += index == 1 ? 2 : 1;
            
            NSLog(@"%@",NSStringFromCGRect(v.frame));
        }
    }
    
     self.composeBtn.frame = CGRectOffset(rect, w * 2, 0);
}

- (void)layoutSubviews {

    [super layoutSubviews];
    
    [self setupUI];
}

@end
